package de.androidschoice.androids.choice;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;
import de.androidschoice.androids.choice.interfaces.GameScene;

public class TextActivity extends Activity {
	private GameScene gs;
	private int refscene;
	private ImageView imageview1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text);
        Integer number = Integer.valueOf(getIntent().getIntExtra("scenenr", 1));
        this.gs = ((ChoiceApplication)this.getApplication()).getScene(number);
        imageview1 = (ImageView) findViewById(R.id.imageview1);
        createLayout();
    }
    
    @Override
	protected void onStart() {
		String id = ((ChoiceApplication)this.getApplication()).getAndroidPostfix();
		if (id.equals("1")){
			imageview1.setImageResource(R.drawable.android1);
		}
		if (id.equals("2")){
			imageview1.setImageResource(R.drawable.android2);
		}
		if (id.equals("3")){
			imageview1.setImageResource(R.drawable.android3);
		}
		if (id.equals("4")){
			imageview1.setImageResource(R.drawable.android4);
		}
		else{
			imageview1.setImageResource(R.drawable.ic_launcher);
		}
		// TODO Auto-generated method stub
		super.onStart();
	}
    
    public void callNextScene() {
    	Intent intent = new Intent(this, TextActivity.class);
		intent.putExtra("scenenr", refscene);
    	this.startActivity(intent);
    }
    
    public void createLayout() {
//    	Toast.makeText(getApplicationContext(), gs.getText(), Toast.LENGTH_LONG).show();
    
		((TextView) findViewById(R.id.scenetext)).setText(gs.getText());
		LinearLayout llayout = (LinearLayout) findViewById(R.id.choiceButtons);
    	for (int i=0; i < gs.getGameSceneChoices().size(); i++) {
    		Button button = new Button(this);
    		String buttonText = gs.getGameSceneChoices().get(i).getGameSceneChoiceText();
    		this.refscene = gs.getGameSceneChoices().get(i).getReferencedGameSceneNumber();
    		button.setText(buttonText);
    		button.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
//					callNextScene();
				}
			});
    		llayout.addView(button);
    	}
    }
}
